﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ST.Dal
{
    public class DbExpress
    {
        private string _columnName;
        private string _columnValue;
        private EExpressType _eExpressType;
        public DbExpress(string columnName,string columnValue,EExpressType eType) {
            this._columnName = columnName;
            this._columnValue = columnValue;
            this._eExpressType = eType;
        }
        public string GetWhereCondition(List<DbExpress> list)
        {
            if (list.Count <= 0)
                return null;
            StringBuilder sb = new StringBuilder();
            string temp = string.Empty;
            foreach (DbExpress express in list)
            {
                temp = this.GetOneConditon(express);
                if (string.IsNullOrEmpty(temp))
                    continue;
                sb.AppendFormat(" AND {0}",temp);
            }
            return sb.ToString();
        }
        private string GetOneConditon(DbExpress express)
        {
            if (express == null)
                return null;
            string reValue = string.Empty;
            switch (express._eExpressType)
            {
                case EExpressType.Eq:
                    reValue = string.Format(" {0} = {1}",express._columnName,express._columnValue);
                    break;
                case EExpressType.Neq:
                    reValue = string.Format(" {0} != {1}", express._columnName, express._columnValue);
                    break;
            }
            return reValue;
        }
        
    }
}
